package com.czkt.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.czkt.pojo.vo.StorageVo;
import com.czkt.service.IStorageService;
import com.czkt.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/storage")
public class StorageController {
    @Autowired
    IStorageService storageService;
    @Autowired
    PageUtils<StorageVo> pageUtils;

    @RequestMapping("/list")
    public Object list(@RequestParam(defaultValue = "") String prodName, String stkWarehouse, @RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "2") Integer pageSize, Model model) {
        IPage<StorageVo> page = new Page<>(pageIndex, pageSize);

        StorageVo storageVo = new StorageVo();
        if (StringUtils.hasText(prodName)) {
            storageVo.getProduct().setProdName(prodName);
        }
        storageVo.setStkWarehouse(stkWarehouse);

        IPage<StorageVo> page1 = storageService.selectAllList(page, storageVo);

        BeanUtils.copyProperties(page1, pageUtils);

        model.addAttribute("storagePage", pageUtils);
        model.addAttribute("prodName", prodName);
        model.addAttribute("stkWarehouse", stkWarehouse);

        return "storage/list";
    }

}
